﻿/**
 * Created by Administrator on 2017/8/21.
 */
define(['api'],function (api) {
    var TradedList = {
        name: 'traded-list',
        template: ''
        + '<div class="see-record closingRecord">'
        + '    <div class="see-record-box">'
        + '        <div class="see-record-center">'
        + '            <i-table :columns="tradedListHead" :data="tradedList"  ref="table"></i-table>'
        + '        </div>'
        + '    </div>'
        + '</div>',
        props: {
        },
        data: function () {
            return {
                tradedListHead: [
                    {
                        title: '成交时间',
                        key: 'TradedTime',
                    },
                    {
                        title: '成交房源',
                        key: 'TradedHouseDescribe',
                    },
                    {
                        title: '销售员',
                        key: 'VisitorName',
                    },
                    {
                        title: '面积',
                        key: 'TradedHouseArea',
                    },
                    {
                        title: '成交价格',
                        key: 'TradedPrice',
                    },
                    {
                        title: '操作',
                        key: 'operation',
                        render: (function (params) {
                            return (
                                ' <Tooltip placement="top" content="查看"><p class="eyes p-click" type="primary" v-on:click="operation(tradedList[' + params._index + '].Id)"></p></Tooltip>'
                            )
                        })
                    }
                ],
                tradedList: [
                    {
                        closingTime: '2017.02.02',
                        closingCustomer: '客户1',
                        salesperson: '销售员A',
                        acreage: '100m²',
                        transactionPrice: '100万',
                        operation: '',
                    },
                    {
                        closingTime: '2017.02.02',
                        closingCustomer: '客户1',
                        salesperson: '销售员A',
                        acreage: '100m²',
                        transactionPrice: '100万',
                        operation: '',
                    },
                ],
            }
        },
        mounted: function () {
            var thisTraded = this;
            //监听getCustomerDetail
            window.bus.$on("getCustomerDetail", function (Id) {
                thisTraded.customerId = Id;
                thisTraded.getTradedList(Id);
            });
            //监视submitVisitRecordSuccess
            window.bus.$on("submitVisitRecordSuccess", function () {
                thisTraded.getTradedList(thisTraded.customerId);
            });
        },
        methods: {
            getTradedList: function (Id) {
                var thisTraded = this;
                api.Get_Visit_Record_Of_Traded({customerId: Id})
                    .done(function (data) {
                        if (data.IsSuccess) {
                            thisTraded.tradedList = data.ResultObject;
                        } else {
                            thisTraded.$Message.error(data.ErrMsg);
                        }
                    })
                    .fail(function () {
                        thisTraded.$Message.error('查询出错');
                    });
            },
            operation: function (Id) {
                //触发TradedOperation
                window.bus.$emit("TradedOperation", Id);
            }
        },
    };
    return TradedList;
});

